<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>菜单管理</title>
    <!-- 引入样式 -->
    <!--<link rel="stylesheet" href="../plugins/elementui/index.css">-->
     <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!--<link rel="stylesheet" href="../plugins/elementui/bbb.css">-->
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">

</head>
<body>
<div id="app">
    <div class="content-header">
        <h1>系统管理
            <small>菜单管理</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item>首页</el-breadcrumb-item>
            <el-breadcrumb-item>系统管理</el-breadcrumb-item>
            <el-breadcrumb-item>菜单管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="菜单名称" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button @click="findPage()">查询</el-button>
                <el-button type="primary" @click="handleCreate()">新建</el-button>
            </div>
            <el-table :data="tableData" style="width:100%" row-key="id" border lazy :load="load"
                      :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
                <el-table-column prop="name" label="菜单名称" width="180" align="center"></el-table-column>
                <el-table-column prop="linkUrl" label="访问路径" width="180" align="center"></el-table-column>
                <el-table-column prop="path" label="路径级别" align="center"></el-table-column>
                <el-table-column prop="parentMenuId" label="自关联id" align="center"></el-table-column>
                <el-table-column prop="level" label="菜单级别" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!--新增表单弹窗-->
            <div class="add-form">
                <el-dialog title="新增菜单项" :visible.sync="dialogFormVisible">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="菜单名称" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="访问路径" prop="linkUrl">
                                    <el-input v-model="formData.linkUrl"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="路径级别" prop="path">
                                    <el-input v-model="formData.path"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="优先级" prop="priority">
                                    <el-input v-model="formData.priority"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="自关联Id" prop="parentMenuId">
                                    <el-select v-model="formData.parentMenuId" placeholder="请选择关联的菜单">
                                        <el-option label="会员管理" value="1"></el-option>
                                        <el-option label="预约管理" value="5"></el-option>
                                        <el-option label="健康评估" value="11"></el-option>
                                        <el-option label="统计分析" value="13"></el-option>
                                        <el-option label="系统设置" value="15"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="菜单级别" prop="level">
                                    <el-input v-model="formData.level"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="图标">
                                    <el-input v-model="formData.icon" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="注意事项">
                                    <el-input v-model="formData.attention" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
            <!-- 编辑标签弹层 -->
            <div class="edit-form">
                <el-dialog title="编辑检查项" :visible.sync="dialogFormVisible4Edit">
                    <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="菜单名称" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="访问路径" prop="linkUrl">
                                    <el-input v-model="formData.linkUrl"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="路径级别" prop="path">
                                    <el-input v-model="formData.path"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="优先级" prop="priority">
                                    <el-input v-model="formData.priority"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="自关联Id" prop="parentMenuId">
                                    <el-select v-model="formData.parentMenuId">
                                        <el-option label="1" value="1"></el-option>
                                        <el-option label="2" value="2"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="菜单级别" prop="level">
                                    <el-input v-model="formData.level"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="图标">
                                    <el-input v-model="formData.icon" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="注意事项">
                                    <el-input v-model="formData.attention" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!--引入组件库 -->
<script src="../js/vue.js"></script>
<!--<script src="../plugins/elementui/index.js"></script>-->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<!--<script src="../plugins/elementui/aaa.js"></script>-->
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 100,//每页显示的记录数
                total: 0,//总记录数(后台计算)
                queryString: null,//查询条件
            },

            tableData:[],
            formData: {},//表单数据
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit: false,//编辑表单是否可见
            rules: {//校验规则
                name: [{required: true, message: '项目编码为必填项', trigger: 'blur'}],
                linkUrl: [{required: true, message: '项目名称为必填项', trigger: 'blur'}],
                path: [{required: true, message: '项目名称为必填项', trigger: 'blur'}],
                priority: [{required: true, message: '项目名称为必填项', trigger: 'blur'}],
                parentMenuId: [{required: true, message: '项目名称为必填项', trigger: 'blur'}],
                level: [{required: true, message: '项目名称为必填项', trigger: 'blur'}]
            }
        },
        methods: {

            //切换页码
            handleCurrentChange(currentPage) {
                //设置最新页码
                this.pagination.currentPage = currentPage;
                //调用分页查询
                this.findPage();
            },
            //重置表单
            resetForm() {
                this.formData = {};
            },
            // 弹出添加窗口
            handleCreate() {
                //弹出新增窗口
                this.dialogFormVisible = true;
                this.resetForm();
            },
            //弹出编辑窗口
            handleUpdate(row) {
                this.dialogFormVisible4Edit = true;
                //回显当前数据
                axios.get("/menu/findById.do?id=" + row.id).then(resp => {
                    if (resp.data.flag) {
                        this.formData = resp.data.data;
                    } else {
                        this.$message.error(resp.data.message);
                    }
                })
            },
            //编辑
            handleEdit() {
                //验证表单
                this.$refs['dataEditForm'].validate((valid) => {
                    if (valid) {
                        axios.post("/menu/edit.do", this.formData).then(resp => {
                            if (resp.data.flag) {
                                this.$message({
                                    type:"success",
                                    message:"修改成功"
                                })
                            } else {
                                this.$message.error(resp.data.message);
                                return false;
                            }
                        }).finally(() => {
                            this.dialogFormVisible4Edit = false;
                            this.findPage();

                        })
                    } else {
                        this.$message.error("数据验证失败")
                    }
                })
            },
            //新增
            handleAdd() {
                //进行表单验证
                this.$refs['dataAddForm'].validate((valid) => {
                    if (valid) {
                        //验证通过,发送请求
                        //  console.log(this.formData);
                        axios.post("/menu/add.do", this.formData).then(resp => {
                            //关闭新增窗口
                            this.dialogFormVisible = false;
                            if (resp.data.flag) {
                                //执行成功
                                //新增成功后，重新调用分页查询方法，查询出最新的数据
                                this.findPage();
                                this.$message({
                                    type: 'success',
                                    message: "新增菜单项成功"
                                });
                            } else {
                                this.$message.error(resp.data.message);
                            }
                        })
                    } else {
                        //校验不通过
                        this.$message.error("数据校验失败,请输入正确的数据");
                        return false
                    }
                })
            },
            //删除
            handleDelete(row) {
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get("/menu/delete.do?id=" + row.id).then(resp => {
                        if (resp.data.flag) {
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            })
                        } else {
                            this.$message.error(resp.data.message);
                        }
                    }).finally(() => {
                        this.findPage()
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            //分页查询
            findPage() {
                //发送ajax请求，提交分页相关请求参数（页码、每页显示记录数、查询条件）
                var param = {
                    currentPage: this.pagination.currentPage,//当前页
                    pageSize: this.pagination.pageSize,//页面容量
                    queryString: this.pagination.queryString//查询条件
                };
                axios.post("/menu/findPage.do", param).then(resp => {
                    //解析Controller响应回的数据，为模型数据赋值
                   this.pagination.total = resp.data.total;
                   this.tableData = resp.data.rows;
                })
            },
            load(tree,treeNode,resolve){

            }
        },
        created(){
            this.findPage()
        }

    })
</script>
</html>